//
//  PhotoTopicView.m
//  YoursShow
//
//  Created by Roc on 11-4-12.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "PhotoTopicView.h"
#import "Topic.h"

#import "TitleBarView.h"

@implementation PhotoTopicView
@synthesize topicViewdelegate = _topicViewDelegate;

@synthesize topic = _topic;
@synthesize image = _image;

///////////////////////////////////////////////////////////////////////////////////////////////////
- (id)initWithFrame:(CGRect)frame topic:(id<PhotoTopic>)topic{
    if ((self = [super initWithFrame:frame])) {
        self.topic = topic;
        
        self.contentMode = UIViewContentModeRedraw;
        
        _image = [UIImage imageNamed:_topic.src];
        CGRect titleRect = CGRectMake(0, frame.size.height-60-5, frame.size.width, 60);
        TitleBarView* titleBar = [[TitleBarView alloc] initWithFrame:titleRect 
                                                               title: _topic.title];
        
        [self addSubview:titleBar];
        [titleBar release];
    }
    
    return self;
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)dealloc {
    self.topic = nil;
    
    [super dealloc];
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];
    
    if (_image != nil) {
        [_image drawInRect:rect];
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touchesEnded called.");
    if (_topicViewDelegate) {
        [_topicViewDelegate onTap:self];
    }
}
@end
